package com.yq.spbYq.mapper;

import com.yq.spbYq.ViolationRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ViolationRecordMapper {

    // 查询所有违规记录
    @Select("SELECT * FROM violation_record")
    @Results({
            @Result(property = "vrId", column = "vr_id"),
            @Result(property = "vrResidentId", column = "vr_resident_id"),
            @Result(property = "vrDescription", column = "vr_description"),
            @Result(property = "vrTime", column = "vr_time"),
            @Result(property = "vrLocation", column = "vr_location"),
            @Result(property = "vrResult", column = "vr_result")
    })
    List<ViolationRecord> selectAllRecords();

    // 根据ID查询违规记录
    @Select("SELECT * FROM violation_record WHERE vr_id = #{vrId}")
    @Results({
            @Result(property = "vrId", column = "vr_id"),
            @Result(property = "vrResidentId", column = "vr_resident_id"),
            @Result(property = "vrDescription", column = "vr_description"),
            @Result(property = "vrTime", column = "vr_time"),
            @Result(property = "vrLocation", column = "vr_location"),
            @Result(property = "vrResult", column = "vr_result")
    })
    ViolationRecord selectRecordById(Integer vrId);

    // 新增违规记录
    @Insert("INSERT INTO violation_record(vr_resident_id, vr_description, vr_time, vr_location, vr_result) VALUES(#{vrResidentId}, #{vrDescription}, #{vrTime}, #{vrLocation}, #{vrResult})")
    int insertRecord(ViolationRecord record);

    // 更新违规记录
    @Update("UPDATE violation_record SET vr_resident_id = #{vrResidentId}, vr_description = #{vrDescription}, vr_time = #{vrTime}, vr_location = #{vrLocation}, vr_result = #{vrResult} WHERE vr_id = #{vrId}")
    int updateRecord(ViolationRecord record);

    // 根据ID删除违规记录
    @Delete("DELETE FROM violation_record WHERE vr_id = #{vrId}")
    int deleteRecordById(Integer vrId);
}